<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of VMT_MBBathy</title>
  <meta name="keywords" content="VMT_MBBathy">
  <meta name="description" content="Computes the multibeam bathymetry from the four beams of the ADCP">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
  <script type="text/javascript">
    if (top.frames.length == 0) { top.location = "../index.html"; };
  </script>
</head>
<body>
<a name="_top"></a>
<!-- menu.html trunk -->
<h1>VMT_MBBathy
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>Computes the multibeam bathymetry from the four beams of the ADCP</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function [A] = VMT_MBBathy(z,A,savefile,beamAng,magVar,wsedata,saveaux) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment"> Computes the multibeam bathymetry from the four beams of the ADCP
 using a script by D.Mueller (USGS). Beam depths are computed for each
 transect prior to any averaging or mapping.

 Added the ability to export timestamps, pitch, roll, and heading
 (2/1/10)

 Added an identifier for each individual transect to the csv output
(FEL, 6/14/12)

 V3 Adds capability to handle timeseries of WSE, PRJ 8-7-12

 P.R. Jackson, USGS, 8-7-12</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="VMT.html" class="code" title="function varargout = VMT(varargin)">VMT</a>	--- THE VELOCITY MAPPING TOOLBOX ---</li></ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [A] = VMT_MBBathy(z,A,savefile,beamAng,magVar,wsedata,saveaux)</a>
0002 <span class="comment">% Computes the multibeam bathymetry from the four beams of the ADCP</span>
0003 <span class="comment">% using a script by D.Mueller (USGS). Beam depths are computed for each</span>
0004 <span class="comment">% transect prior to any averaging or mapping.</span>
0005 <span class="comment">%</span>
0006 <span class="comment">% Added the ability to export timestamps, pitch, roll, and heading</span>
0007 <span class="comment">% (2/1/10)</span>
0008 <span class="comment">%</span>
0009 <span class="comment">% Added an identifier for each individual transect to the csv output</span>
0010 <span class="comment">%(FEL, 6/14/12)</span>
0011 <span class="comment">%</span>
0012 <span class="comment">% V3 Adds capability to handle timeseries of WSE, PRJ 8-7-12</span>
0013 <span class="comment">%</span>
0014 <span class="comment">% P.R. Jackson, USGS, 8-7-12</span>
0015 
0016 <span class="comment">%% Start</span>
0017 <span class="keyword">try</span>
0018     <span class="comment">%disp('Computing corrected beam depths')</span>
0019     <span class="keyword">if</span> isstruct(wsedata)
0020         <span class="keyword">if</span> length(wsedata.elev) == 1
0021             <span class="comment">%disp('WSE is a constant value')</span>
0022             wsefiletype = 0;
0023         <span class="keyword">else</span>
0024             <span class="comment">%disp('WSE is a timeseries')</span>
0025             wsefiletype = 1;
0026         <span class="keyword">end</span>
0027     <span class="keyword">else</span>
0028         <span class="comment">%disp('WSE is a constant value')</span>
0029         warning off
0030         wsedata.elev = wsedata;
0031         wsefiletype = 0;
0032         warning on
0033     <span class="keyword">end</span>
0034     
0035     <span class="comment">%% Step through each transect in the given set</span>
0036     <span class="comment">%figure(1); clf</span>
0037     <span class="keyword">for</span> zi = 1 : z
0038         
0039         <span class="comment">% Work on the WSE if a vector</span>
0040         <span class="comment">%WSE vector must have a value for each ensemble, so interpolate given</span>
0041         <span class="comment">%values to ensemble times</span>
0042         
0043         <span class="keyword">if</span> wsefiletype  <span class="comment">%only process as vector if loaded file rather than single value</span>
0044             <span class="comment">%Build an ensemble time vector</span>
0045             enstime = datenum([A(zi).Sup.year+2000 A(zi).Sup.month A(zi).Sup.day<span class="keyword">...</span>
0046                 A(zi).Sup.hour A(zi).Sup.minute (A(zi).Sup.second+A(zi).Sup.sec100./100)]);
0047             <span class="comment">%Had to add 2000 to year--will not work for years &lt; 2000</span>
0048             <span class="comment">%Check the times (for debugging)</span>
0049             <span class="keyword">if</span> 0
0050                 obs_start = datestr(wsedata.obstime(1))
0051                 obs_end = datestr(wsedata.obstime(end))
0052                 
0053                 ens_start = datestr(enstime(1))
0054                 ens_end = datestr(enstime(end))
0055             <span class="keyword">end</span>
0056             
0057             <span class="comment">% Interpolate the WSE values to the ENS times</span>
0058             wse = interp1(wsedata.obstime,wsedata.elev,enstime);
0059             <span class="comment">% Plot for debugging</span>
0060             <span class="keyword">if</span> 0
0061                 figure(1); hold on
0062                 plot(enstime,wse,<span class="string">'k-'</span>)
0063                 datetick(<span class="string">'x'</span>,13)
0064                 ylabel(<span class="string">'WSE, in meters'</span>)
0065             <span class="keyword">end</span>
0066         <span class="keyword">else</span>
0067             wse = wsedata.elev; <span class="comment">%Single value</span>
0068         <span class="keyword">end</span>
0069         
0070         <span class="comment">% Compute position and elevation of each beam depth</span>
0071         [exyz] = depthxyz(A(zi).Nav.depth,A(zi).Sup.draft_cm,<span class="keyword">...</span>
0072             A(zi).Sensor.pitch_deg,A(zi).Sensor.roll_deg,<span class="keyword">...</span><span class="comment">.</span>
0073             A(zi).Sensor.heading_deg,beamAng,<span class="keyword">...</span>
0074             <span class="string">'m'</span>,A(zi).Comp.xUTMraw,A(zi).Comp.yUTMraw,wse,A(zi).Sup.ensNo);  <span class="comment">%magVar,removed 4-8-10</span>
0075         
0076         <span class="comment">%Build the auxillary data matrix</span>
0077         <span class="keyword">if</span> saveaux
0078             auxmat = [A(zi).Sup.year+2000 A(zi).Sup.month A(zi).Sup.day<span class="keyword">...</span>
0079                 A(zi).Sup.hour A(zi).Sup.minute (A(zi).Sup.second+A(zi).Sup.sec100./100) <span class="keyword">...</span>
0080                 A(zi).Sensor.heading_deg A(zi).Sensor.pitch_deg A(zi).Sensor.roll_deg <span class="keyword">...</span>
0081                 repmat(zi,size(A(zi).Sup.year))]; <span class="comment">% Added transect #(zi) FLE 6/14/12    %Had to add 2000 to year--will not work for years &lt; 2000</span>
0082             auxmat2 = [];
0083             <span class="keyword">for</span> i = 1:length(A(zi).Sup.ensNo);
0084                 dum = repmat(auxmat(i,:),4,1);
0085                 auxmat2 = cat(1,auxmat2,dum);
0086             <span class="keyword">end</span>
0087             clear auxmat dum enstime wse
0088         <span class="keyword">end</span>
0089         
0090         <span class="comment">% Store results</span>
0091         idxmbb = find(~isnan(exyz(:,4))&amp; ~isnan(exyz(:,2)));
0092         <span class="keyword">if</span> zi==1
0093             zmbb=[exyz(idxmbb,1) exyz(idxmbb,2)<span class="keyword">...</span>
0094                 exyz(idxmbb,3) exyz(idxmbb,4)];
0095             <span class="keyword">if</span> saveaux
0096                 auxmbb = auxmat2(idxmbb,:);
0097             <span class="keyword">end</span>
0098         <span class="keyword">else</span>
0099             zmbb=cat(1,zmbb,[exyz(idxmbb,1)<span class="keyword">...</span>
0100                 exyz(idxmbb,2) exyz(idxmbb,3) exyz(idxmbb,4)]);
0101             <span class="keyword">if</span> saveaux
0102                 auxmbb = cat(1,auxmbb,auxmat2(idxmbb,:));
0103             <span class="keyword">end</span>
0104         <span class="keyword">end</span>
0105         
0106         A(zi).Comp.exyz = exyz(idxmbb,:);
0107         
0108         
0109         clear idxmbb exyz;
0110         <span class="comment">%pack;</span>
0111     <span class="keyword">end</span>
0112     
0113     
0114     <span class="comment">%% Save the data</span>
0115     
0116     <span class="keyword">if</span> 1
0117         <span class="comment">%disp('Exporting multibeam bathymetry')</span>
0118         <span class="comment">%disp([savefile(1:end-4) '_mbxyz.csv'])</span>
0119         outfile = [savefile(1:end-4) <span class="string">'.csv'</span>];
0120         <span class="keyword">if</span> saveaux
0121             outmat = [zmbb auxmbb];
0122             ofid   = fopen(outfile, <span class="string">'wt'</span>);
0123             outcount = fprintf(ofid,<span class="string">'EnsNo,     Easting_WGS84_m,    Northing_WGS84_m,  Elev_m,  Year,  Month,  Day,  Hour,  Minute,  Second,  Heading_deg,  Pitch_deg,  Roll_deg,  Transect\n'</span>); <span class="comment">% Modified to output transect # FLE 6/14/12</span>
0124             outcount = fprintf(ofid,<span class="string">'%6.0f, %14.2f, %14.2f, %8.2f, %4.0f, %2.0f, %2.0f, %2.0f, %2.0f, %2.2f, %3.3f, %3.3f, %3.3f, %3.0f\n'</span>,outmat');
0125             fclose(ofid);
0126         <span class="keyword">else</span>
0127             outmat = zmbb;
0128             ofid   = fopen(outfile, <span class="string">'wt'</span>);
0129             outcount = fprintf(ofid,<span class="string">'EnsNo,     Easting_WGS84_m,    Northing_WGS84_m,  Elev_m\n'</span>);
0130             outcount = fprintf(ofid,<span class="string">'%6.0f, %14.2f, %14.2f, %8.2f\n'</span>,outmat');
0131             fclose(ofid);
0132         <span class="keyword">end</span>
0133         <span class="comment">%dlmwrite([savefile(1:end-4) '_mbxyz.csv'],outmat,'precision',15);</span>
0134     <span class="keyword">end</span>
0135 <span class="keyword">catch</span> err
0136      <span class="keyword">if</span> isdeployed
0137         errLogFileName = fullfile(pwd,<span class="keyword">...</span>
0138             [<span class="string">'errorLog'</span> datestr(now,<span class="string">'yyyymmddHHMMSS'</span>) <span class="string">'.txt'</span>]);
0139         msgbox({[<span class="string">'An unexpected error occurred. Error code: '</span> err.identifier];<span class="keyword">...</span>
0140             [<span class="string">'Error details are being written to the following file: '</span>];<span class="keyword">...</span>
0141             errLogFileName},<span class="keyword">...</span>
0142             <span class="string">'VMT Status: Unexpected Error'</span>,<span class="keyword">...</span>
0143             <span class="string">'error'</span>);
0144         fid = fopen(errLogFileName,<span class="string">'W'</span>);
0145         fwrite(fid,err.getReport(<span class="string">'extended'</span>,<span class="string">'hyperlinks'</span>,<span class="string">'off'</span>));
0146         fclose(fid);
0147         rethrow(err)
0148     <span class="keyword">else</span>
0149         msgbox([<span class="string">'An unexpected error occurred. Error code: '</span> err.identifier],<span class="keyword">...</span>
0150             <span class="string">'VMT Status: Unexpected Error'</span>,<span class="keyword">...</span>
0151             <span class="string">'error'</span>);
0152         rethrow(err);
0153     <span class="keyword">end</span>    
0154 <span class="keyword">end</span></pre></div>
<hr><address>Generated on Wed 04-Jun-2014 14:21:02 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2005</address>
</body>
</html>